<%@ page import="java.sql.Statement" import="java.sql.ResultSet" import="java.sql.Connection" %> 
<%@ page import="java.sql.*,java.util.*,java.text.*,java.text.SimpleDateFormat" %>
<%@page import="connection.DBConnection"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h2 align="center">Search Results</h2>
<%
DBConnection dbc=new DBConnection();
Connection con=dbc.getNewConnection();
Statement st = null;
ResultSet rs = null;
String dt="",in="",ch="",nm="",nr="";
double st1=0.0;

String selected=(String) request.getAttribute("search");

	%>
  <table border=1 align="center">
  <tr><td>Date</td><td>Voucher Type</td><td>Voucher Number</td><td>Particulars</td><td>Cheque Number</td><td> Amount</td><td>Narration</td></tr>
<%
try
{
	  st=con.createStatement() ;
	  rs=st.executeQuery("select date,innum, scname, stota from salesvoucher2 where stota like '"+selected+"%' or innum like '"+selected+"%'  ;");
while(rs.next()){
	
	 dt =rs.getString(1);
	 in =rs.getString(2);
	
	 nm=rs.getString(3);

	 st1=rs.getDouble(4);
	
	%>
	<tr><td><%=dt %></td>
	<td>Sales Voucher</td><td><%=in %></td><td><%=nm %></td><td>-</td><td><%=st1 %></td><td>-</td>
	</tr>
	
	<%
}
}
catch(Exception e){
	
}
	%>
	
	
	<%
try
{
	  st=con.createStatement() ;
	  rs=st.executeQuery("select date,pvinno, pvsname, pvtota from purchasevoucher2 where pvtota like '"+selected+"%' or pvinno like '"+selected+"%'  ;");
while(rs.next()){
	
	 dt =rs.getString(1);
	 in =rs.getString(2);
	
	 nm=rs.getString(3);

	 st1=rs.getDouble(4);
	%>
	<tr><td><%=dt %></td>
	<td>Purchase Voucher</td><td><%=in %></td><td><%=nm %></td><td>-</td><td><%=st1 %></td><td>-</td>
	</tr>
	
	<%
}
}
catch(Exception e){
	
}
	%>
	
	<%
try
{
	  st=con.createStatement() ;
	  rs=st.executeQuery("select date,renum,rcheque, raccname, ramount,rnar from receiptsvoucher2 where ramount like '"+selected+"%' or renum like '"+selected+"%' or rcheque like '"+selected+"%' or rnar like '"+selected+"%'   ;");
while(rs.next()){
	
	 dt =rs.getString(1);
	 in =rs.getString(2);
	 ch =rs.getString(3);
	 nm=rs.getString(4);

	 st1=rs.getDouble(5);
	nr=rs.getString(6);

	%>
	<tr><td><%=dt %></td>
	<td>Receipt</td><td><%=in %></td><td><%=nm %></td><td><%=ch %></td><td><%=st1 %></td><td><%=nr %></td>
	</tr>
	
	<%
}
}
catch(Exception e){
	
}
	%>
	
	
	<%
try
{
	  st=con.createStatement() ;
	  rs=st.executeQuery("select date,pyenum,pycheque, pyaccname, pyamount,pynar from paymentvoucher2 where pyamount like '"+selected+"%' or pyenum like '"+selected+"%' or pycheque like '"+selected+"%' or pynar like '"+selected+"%'   ;");
while(rs.next()){
	
	 dt =rs.getString(1);
	 in =rs.getString(2);
	ch =rs.getString(3);
	 nm=rs.getString(4);

	 st1=rs.getDouble(5);
	 nr=rs.getString(6);

	%>
	<tr><td><%=dt %></td>
	<td>Payment</td><td><%=in %></td><td><%=nm %></td><td><%=ch %></td><td><%=st1 %></td><td><%=nr %></td>
	</tr>
	
	<%
}
}
catch(Exception e){
	
}
	%>
	<%
try
{
	  st=con.createStatement() ;
	  rs=st.executeQuery("select date,jname,jaccdeb, jamount1,jnar from journalvoucher2 where jamount1 like '"+selected+"%' or jname like '"+selected+"%' or  jnar like '"+selected+"%'   ;");
while(rs.next()){
	
	 dt =rs.getString(1);
	in =rs.getString(2);
	
	 nm=rs.getString(3);

	 st1=rs.getDouble(4);
	 nr=rs.getString(5);
	%>
	<tr><td><%=dt %></td>
	<td>Journal</td><td><%=in %></td><td><%=nm %></td><td>-</td><td><%=st1 %></td><td><%=nr %></td>
	</tr>
	
	<%
}
}
catch(Exception e){
	
}
	%>
	
	<%
try
{
	  st=con.createStatement() ;
	  rs=st.executeQuery("select date,jname,jacccred, jamount2,jnar from journalvoucher2 where jamount2 like '"+selected+"%' or jname like '"+selected+"%' or  jnar like '"+selected+"%'   ;");
while(rs.next()){
	
	 dt =rs.getString(1);
	in =rs.getString(2);
	
	 nm=rs.getString(3);

	 st1=rs.getDouble(4);
	 nr=rs.getString(5);
	%>
	<tr><td><%=dt %></td>
	<td>Journal</td><td><%=in %></td><td><%=nm %></td><td>-</td><td><%=st1 %></td><td><%=nr %></td>
	</tr>
	
	<%
}
}
catch(Exception e){
	
}
	%>
	<%
try
{
	  st=con.createStatement() ;
	  rs=st.executeQuery("select date,dbinno, dbsname, dbtotal from debitnote where dbtotal like '"+selected+"%' or dbinno like '"+selected+"%' ;");
while(rs.next()){
	
	 dt =rs.getString(1);
	 in =rs.getString(2);
	 nm=rs.getString(3);

	st1=rs.getDouble(4);
	

	%>
	<tr><td><%=dt %></td>
	<td>Debit Note Voucher</td><td><%=in %></td><td><%=nm %></td><td>-</td><td><%=st1 %></td><td>-</td>
	</tr>
	
	<%
}
}
catch(Exception e){
	
}
	%>
		<%
try
{
	  st=con.createStatement() ;
	  rs=st.executeQuery("select date,cdinno, cdcname, cdtotal from creditnote where cdtotal like '"+selected+"%' or cdinno like '"+selected+"%' ;");
while(rs.next()){
	
	 dt =rs.getString(1);
	 in =rs.getString(2);
	
	 nm=rs.getString(3);

	 st1=rs.getDouble(4);
	

	%>
	<tr><td><%=dt %></td>
	<td>Credit Note Voucher</td><td><%=in %></td><td><%=nm %></td><td>-</td><td><%=st1 %></td><td>-</td>
	</tr>
	
	<%
}
}
catch(Exception e){
	
}
	%>
	
	<%
try
{
	  st=con.createStatement() ;
	  rs=st.executeQuery("select datecreated,cname, copen from customermaster where copen like '"+selected+"%'  ;");
while(rs.next()){
	
	 dt =rs.getString(1);
	
	 nm=rs.getString(2);

	 st1=rs.getDouble(3);
	

	%>
	<tr><td><%=dt %></td>
	<td>Opening Balance</td><td>-</td><td><%=nm %></td><td>-</td><td><%=st1 %></td><td>-</td>
	</tr>
	
	<%
}
}
catch(Exception e){
	
}
	%>
	
	
	<%
try
{
	  st=con.createStatement() ;
	  rs=st.executeQuery("select datecreated,sname, sopen from suppliermaster where sopen like '"+selected+"%'  ;");
while(rs.next()){
	
	 dt =rs.getString(1);
	
	 nm=rs.getString(2);

	 st1=rs.getDouble(3);
	

	%>
	<tr><td><%=dt %></td>
	<td>Opening Balance</td><td>-</td><td><%=nm %></td><td>-</td><td><%=st1 %></td><td>-</td>
	</tr>
	
	<%
}
}
catch(Exception e){
	
}
	%>
	
	<%
try
{
	  st=con.createStatement() ;
	  rs=st.executeQuery("select datecreated,bname, bopen from bankmaster where bopen like '"+selected+"%'  ;");
while(rs.next()){
	
	dt =rs.getString(1);
	
	 nm=rs.getString(2);

	 st1=rs.getDouble(3);
	

	%>
	<tr><td><%=dt %></td>
	<td>Opening Balance</td><td>-</td><td><%=nm %></td><td>-</td><td><%=st1 %></td><td>-</td>
	</tr>
	
	<%
}
}
catch(Exception e){
	
}
	%>
	<%
try
{
	  st=con.createStatement() ;
	  rs=st.executeQuery("select datecreated,gname, gbal from generalledger2 where gbal like '"+selected+"%' or gname like '"+selected+"%'  ;");
while(rs.next()){
	
	 dt =rs.getString(1);
	
	 nm=rs.getString(2);

	 st1=rs.getDouble(3);
	

	%>
	<tr><td><%=dt %></td>
	<td>Opening Balance</td><td>-</td><td><%=nm %></td><td>-</td><td><%=st1 %></td><td>-</td>
	</tr>
	
	<%
}
}
catch(Exception e){
	
}
	%>
	
	<%
try
{
	  st=con.createStatement() ;
	  rs=st.executeQuery("select datecreated,stname, sopen from stockmaster where sopen like '"+selected+"%'  ;");
while(rs.next()){
	
	 dt =rs.getString(1);
	
	 nm=rs.getString(2);

	 st1=rs.getDouble(3);
	

	%>
	<tr><td><%=dt %></td>
	<td>Opening Balance</td><td>-</td><td><%=nm %></td><td>-</td><td><%=st1 %></td><td>-</td>
	</tr>
	
	<%
}
}
catch(Exception e){
	
}
	%>
	</table><br>
		
	<% if(dt=="" && in=="" && ch=="" && nm=="" && st1==0 && nr=="")
	{
		out.println("<center><font color=red>No Result found</font></center>");
	}
		
		%>
</body>
</html>